<?php /* Smarty version 2.6.20, created on 2013-05-25 01:50:42
         compiled from _core/_include/module/_mvc/control/handledialogassignee.tpl */ ?>
<?php require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');
smarty_core_load_plugins(array('plugins' => array(array('modifier', 'escape', '_core/_include/module/_mvc/control/handledialogassignee.tpl', 97, false),)), $this); ?>
function HandleDialogAssignee(gui, item, options) {
  this._gui = gui;
  this._item = item;
  
  this._options = options;
  this._popupBox = new PopupBox();

  this._php = (options && options.php) ? options.php : 'customphp/mysqlread.php';
  this._condition = (options && options.condition) ? options.condition : null;
  this._date = (options && options.date) ? options.date : null;
  this._nop = (options && options.nop) ? options.nop : false;
  this._orderTrackId = (options && options.orderTrackId) ? options.orderTrackId : null;
  this._photo = (options && options.photo) ? options.photo : false;
  this._weddingday = (options && options.d) ? options.d : null;
  this._preconUsers = (options && options.preconUsers) ? options.preconUsers : null;
  
  this._createElements();
};

HandleDialogAssignee.prototype._createElements = function() {
  this._loadData();
};

HandleDialogAssignee.prototype._loadData = function() {
  this._users = null;
  this._order = null;
  this._produces = null;
  
  this._retrieveUsers();
  this._retrieveProduces();
};

HandleDialogAssignee.prototype._verifyData = function() {
  if (this._users && this._produces) {
      this._updateElements();
  }
};

HandleDialogAssignee.prototype._retrieveUsers = function() {
  var _self = this;
  /*new RequestUtils()._read('user', null, this._condition, null, null, null, null, function(result, params) { _self._users = result.data;
                                                                                                             _self._verifyData.call(_self);
                                                                                                           }, { php: this._php });
*/
  var args = (this._condition) ?  '&c=' + this._condition : '';
  new RequestUtils()._mysql('v1user_p', args, function(result, params) { _self._users = result.data;
                                                                          _self._verifyData.call(_self);
                                                                        }, {php:this._php});  

};

HandleDialogAssignee.prototype._retrieveOrder = function() {
  var _self = this;
  
  /*new RequestUtils()._read('myorder_p', null, 'd.trackId = \'' + this._orderTrackId + '\'', null, null, null, null, function(result, params) { _self._order = (result.data.length == 1) ? result.data[0] : null;
                                                                                                                                             _self._verifyData.call(_self);
                                                                                                                                           }, { php: this._php });


  
*/
  var args = '&oid=' + this._orderTrackId;
  new RequestUtils()._mysql('v1myorder', args, function(result, params) { _self._order = (result.data.length == 1) ? result.data[0] : null;
                                                                          _self._verifyData.call(_self);
                                                                        }, {php:'customphp/mysqlread.php'});  
};

HandleDialogAssignee.prototype._retrieveProduces = function() {
  var _self = this;

  if (this._date) {
    if (this._orderTrackId) {
      var joins = '&produceusers=1';
      var args = '&c=d.cancelled = 0 AND d.orderTrackId = \'' + this._orderTrackId + '\'' + joins;
      new RequestUtils()._mysql('produce', args, function(result, params) { _self._produces = result.data;
                                                                            _self._verifyData.call(_self);
                                                                          }, { php: Constant.FACTORY + '/customphp/produceread.php' });
    } else {
      this._produces = [];
    }
  } else {
    if (this._orderTrackId) {
      var args = '&c=d.cancelled = 0 AND d.orderTrackId = \'' + this._orderTrackId + '\'';
      new RequestUtils()._mysql('produce', args, function(result, params) { _self._produces = result.data;
                                                                            _self._verifyData.call(_self);
                                                                          }, { php: Constant.FACTORY + '/customphp/produceread.php' });
    } else {
      this._produces = [];
    }
  }
};

HandleDialogAssignee.prototype._updateElements = function() {
  var table, tr, td, radio, input, unique = MiscUtils.unique(), _self = this;
  DlmanageUtils.clear(this._gui);
  
  if (this._item.pi_model == '<?php echo ((is_array($_tmp=@MODEL_NAME_PRECON)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
    this._gui.title.appendChild(document.createTextNode('Select a Date and Time'));
  }
  
  if (this._date) {
  
    if (this._item.pi_model == '<?php echo ((is_array($_tmp=@MODEL_NAME_USER_PHOTOGRAPHER)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' || this._item.pi_model == '<?php echo ((is_array($_tmp=@MODEL_NAME_USER_VIDEOGRAPHER)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' ||
      this._item.pi_model == '<?php echo ((is_array($_tmp=@MODEL_NAME_USER_MAKEUP)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' || this._item.pi_model == '<?php echo ((is_array($_tmp=@MODEL_NAME_USER_LIGHT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
        input = DOMUtils.createInput(null, null, 'text', (this._item.pdate) ? SimpleDate.format(this._item.pdate, true) : '', null);
        input.onclick = function() { var context = this;
                                 _self._changeDate.call(_self, this, (_self._item.pdate) ? _self._item.pdate : SimpleDate.create(), function(sd) { _self._item.pdate = sd; }, true);
                               };
  }else{
    input = DOMUtils.createInput(null, null, 'text', (this._item.when) ? SimpleDate.format(this._item.when, true) : '', null);
    input.onclick = function() { var context = this;
                                 _self._changeDate.call(_self, this, (_self._item.when) ? _self._item.when : SimpleDate.create(), function(sd) { _self._item.when = sd; }, true);
                               };
   }
   
    this._gui.date.appendChild(input);
  }
  
  table = document.createElement('table');
  this._gui.users.appendChild(table);

  if (this._item.pi_model == '<?php echo ((is_array($_tmp=@MODEL_NAME_PRECON)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
    for (var i = 0, il = this._users.length; i < il; i++) {
      var u = this._users[i];
      var exist = false;
      for (var j = 0, jl = this._produces.length; j < jl; j++) {
        var p = this._produces[j];
        for (var k = 0, kl = p.pUsers.length; k < kl; k++) {
          var pUser = p.pUsers[k];
          if (pUser.trackId == u.trackId && p.trackId != this._item.trackId && p.pi_model == this._item.pi_model) {
            exist = true;
          }
        }
      }
      
      
      if (!exist) {
        tr = table.insertRow(-1);
        td = tr.insertCell(-1);
        checkbox = DOMUtils.createInput(unique + '_assingee', null, 'checkbox', '', null);
        checkbox._user = u;
        var check = false;
        for (var m = 0, ml = this._preconUsers.length; m < ml; m++) {
          var user = this._preconUsers[m];
          if (u.trackId == user.trackId) {
            check = true;
          }
        }
        if (check) {
          checkbox.defaultChecked = check;
        } else {
          checkbox.defaultChecked = false;
        }
        checkbox.onclick = function() { var user = DlmanageUtils.renew(this._user);
                                        if (this.checked == true) {
                                          user.produce_id = _self._item.id;
                                          _self._preconUsers[_self._preconUsers.length] = user; 
                                        } else {
                                          user.produce_id = 0;
                                          MiscUtils.remove(_self._preconUsers, user, 'trackId');
                                        }
                                      };
        td.appendChild(checkbox);
        td = tr.insertCell(-1);
        td.appendChild(document.createTextNode(u.account));
      }
    }
  } else {

    var smryArgs = [];
    var smryGui = [];
    for (var i = 0, il = this._users.length; i < il; i++) {
      var u = this._users[i];
      var exist = false;
      for (var j = 0, jl = this._produces.length; j < jl; j++) {
        var p = this._produces[j];
        if (p.user_trackId == u.trackId && p.trackId != this._item.trackId && p.pi_model == this._item.model) {
          exist = true;
        }
      }
      
  if (this._nop) {
    exist = true;
  }
      //console.log(this._item.pi_model);
      if (!exist) {
        tr = table.insertRow(-1);
        td = tr.insertCell(-1);
        radio = DOMUtils.createInput(unique + '_assignee', null, 'radio', null, null);
        radio.checked = (this._item.user_trackId == u.trackId);
        radio._user = u;
        radio.onclick = function() { _self._item.user_trackId = this._user.trackId;
                                     _self._item.user_account = this._user.account; 
                                     _self._item.user_password = this._user.password;
                                     _self._item.user_name = this._user.name;
                                     _self._item.user_email = this._user.email;
                                     _self._item.user_type = this._user.type;
                                   };
        td.appendChild(radio);
        td = tr.insertCell(-1);
        td.appendChild(document.createTextNode(u.account));
      }
    }
  }
//        if (this._photo) {
//          if (this._order.type == '<?php echo ((is_array($_tmp=@ORDER_TYPE_WEDDING)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
//            if (u.skill.employmentType != 1) {
//              td.appendChild(document.createTextNode(' ($' + u.skill.pWedding + '/ h' + ((u.skill.pCusPhoto) ? ', 客片' : '') + ')'));
//            } else {
//              td.appendChild(document.createTextNode(' (Fulltime'));
//              var span = document.createElement('span');
//              span.id = unique + '_' + i + '_' + u.account;
//              td.appendChild(span);
//              
//              smryGui[smryGui.length] = document.getElementById(unique + '_' + i + '_' + u.account);
//              smryArgs[smryArgs.length] = {name: unique + '_' + i + '_' + u.account, trackId: u.trackId };
//              td.appendChild(document.createTextNode(((u.skill.pCusPhoto) ? ', 客片' : '') + ')'));
//            }
//          } else if (this._order.type == '<?php echo ((is_array($_tmp=@ORDER_TYPE_PREWEDDING)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
//            if (u.skill.employmentType != 1) {
//              td.appendChild(document.createTextNode(' ($' + u.skill.pPrewedding + '/ h' + ((u.skill.pCusPhoto) ? ', 客片' : '') + ')'));
//            } else {
//              td.appendChild(document.createTextNode(' (Fulltime'));
//              var span = document.createElement('span');
//              span.id = unique + '_' + i + '_' + u.account;
//              td.appendChild(span);
//              
//              smryGui[smryGui.length] = document.getElementById(unique + '_' + i + '_' + u.account);
//              smryArgs[smryArgs.length] = {name: unique + '_' + i + '_' + u.account, trackId: u.trackId };
//              td.appendChild(document.createTextNode(((u.skill.pCusPhoto) ? ', 客片' : '') + ')'));
//            }
//          } else if (this._order.type == '<?php echo ((is_array($_tmp=@ORDER_TYPE_PORTRAIT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
//            if (u.skill.employmentType != 1) {
//              td.appendChild(document.createTextNode(' ($' + u.skill.pPortrait + '/ h' + ((u.skill.pCusPhoto) ? ', 客片' : '') + ')'));
//            } else {
//              td.appendChild(document.createTextNode(' (Fulltime'));
//              var span = document.createElement('span');
//              span.id = unique + '_' + i + '_' + u.account;
//              td.appendChild(span);
//              
//              smryGui[smryGui.length] = document.getElementById(unique + '_' + i + '_' + u.account);
//              smryArgs[smryArgs.length] = {name: unique + '_' + i + '_' + u.account, trackId: u.trackId };
//              td.appendChild(document.createTextNode(((u.skill.pCusPhoto) ? ', 客片' : '') + ')'));
//            }
//          } else if (this._order.type == '<?php echo ((is_array($_tmp=@ORDER_TYPE_ENGAGEMENT)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
//            if (u.skill.employmentType != 1) {
//              td.appendChild(document.createTextNode(' ($' + u.skill.pEngagement + '/ h' + ((u.skill.pCusPhoto) ? ', 客片' : '') + ')'));
//            } else {
//              td.appendChild(document.createTextNode(' (Fulltime'));
//              var span = document.createElement('span');
//              span.id = unique + '_' + i + '_' + u.account;
//              td.appendChild(span);
//              
//              smryGui[smryGui.length] = document.getElementById(unique + '_' + i + '_' + u.account);
//              smryArgs[smryArgs.length] = {name: unique + '_' + i + '_' + u.account, trackId: u.trackId };
//              td.appendChild(document.createTextNode(((u.skill.pCusPhoto) ? ', 客片' : '') + ')'));
//            }
//          }
//        }
//      }
//    }
//    if (this._photo) {
//      new HandleSmryProduce(smryGui, this._users, { args: smryArgs, date: this._order.date});
//    }
};

HandleDialogAssignee.prototype._changeDate = function(label, currentDate, onChangeFunc, showTime) {
  var div, _self = this;
  div = document.createElement('div');
  div.style.left = DOMUtils.findPos(label)[0] + 'px';
  div.style.top = DOMUtils.findPos(label)[1] + 'px';
  this._popupBox._open(div, { pos: DOMUtils.findPos(label) });
  
  var ds = new DateSelect(currentDate, null, { container: div, showTime: showTime });
  ds._selectFunc = function(sd) { _self._selectDate.call(_self, sd, label, onChangeFunc, showTime); };
};

HandleDialogAssignee.prototype._selectDate = function(sd, label, onChangeFunc, showTime) {
  onChangeFunc(sd);
  this._showDate(sd, label, showTime);
  this._popupBox._close();
};

HandleDialogAssignee.prototype._showDate = function(sd, label, showTime) {
  if (sd) { 
    label.value = SimpleDate.format(sd, showTime);
  } else {
    label.value = '';
  }
};